function a = extend2Darray(a, b, direc)%, arrayType)
  % "Intelligently" extend a 2-D array in direction direc = 'H' or 'V' (the default).
  % In other words, given 2-D input arrays a and b and direction direc, append b to a, 
  % increasing a's rows (resp. columns) if direc = 'V' (resp. 'H').  
  %
%   % Optional argument 
%   % arrayType facilitates resolution of ambiguity and more self-documenting calling routines.
  %
  % Author: David Goldsmith, Wash. State Dept. of Ecology, dgol461@ecy.wa.gov
  % Release date: 9/26/2011

%     if nargin < 4
%         if isnumeric(a)
%             arrayType = 'n';
%         elseif ischar(a)
%             arrayType = 'h';
%         elseif iscell(a)
%             arrayType = 'c';
%         elseif isstruct(a)
%             arrayType = 's';
%         else
%             arrayType = 'o';
%         end
%     end
%     
    if nargin < 3
        direc = 'V';
    end
    
    if all(~cellfun(@isempty, {a, b})) ...
                            && ...
       ((strcmpi(direc, 'H') && numel(a(:,1))~=numel(b(:,1))) ...
                            || ...
       (strcmpi(direc, 'V') && numel(a(1,:))~=numel(b(1,:))))
        disp(['Dimension mismatch: could not append second array to first in the direction requested;'...
              char(10) 'inputs unaltered.'])
        return
    end
    
%     try
%         switch arrayType
%             case {'n', 'h'}
    if strcmpi(direc, 'H')
        a(:, end+1:end+numel(b(1,:))) = b;
    else
        a(end+1:end+numel(b(:,1)), :) = b;
    end
%             case 'c'
%                 for i=1:m
%                     a{end+1} = b{i};
%                 end
%             case 's'
%                 n = length(a);
%                 for i=1:m
%                     for field=fieldnames(b(i))'
%                         field = field{:};
%                         a(n+i).(field) = b(i).(field);
%                     end
%                 end
%             case 'o'
%                 n = length(a);
%                 iprops = properties(b);
%                 for i=1:m
%                     for prop=iprops'
%                         prop = prop{:}
%                         if any(isproperty(a, prop))
%                             a(n+i).(prop) = b(i).(prop);
%                         end
%                     end
%                 end
%         end
%     catch ME
%         getReport(ME)
% %        uiwait
%         return
%     end
end